<!-- 新增回款 -->
<template>
  <el-drawer
    v-model="drawerVisible"
    :close-on-click-modal="false"
    :destroy-on-close="true"
    size="1000px"
    :title="drawerProps.title"
  >
    <el-form
      ref="ruleFormRef"
      label-position="top"
      require-asterisk-position="right"
      :inline="true"
      :rules="rules"
      :model="params"
      class="form-inline-wrap"
    >
      <el-form-item label="选择合同" prop="contract">
        <el-select v-model="params.contract" placeholder="请选择合同" clearable>
          <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="款项名称" prop="nameOfPayment">
        <el-select v-model="params.nameOfPayment" placeholder="请选择款项名称" clearable>
          <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="回款金额(元)" prop="returnAmount">
        <el-input v-model="params.returnAmount" placeholder="请输入回款金额" type="number" clearable></el-input>
      </el-form-item>
      <el-form-item label="回款日期">
        <el-date-picker
          v-model="params.paymentDate"
          type="date"
          placeholder="请选择回款日期"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="收款账户" prop="collectionAccount">
        <el-select v-model="params.collectionAccount" placeholder="请选择收款账户" clearable>
          <el-option v-for="item in businessType" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="回款凭证" prop="paymentVoucher">
        <upload-img>
          <template #default>
            将5M以内的文件<br />
            拖拽框内
          </template>
        </upload-img>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
import { ref, reactive, defineEmits } from "vue";
import UploadImg from "../../ClientMaterials/components/UploadImg.vue";

const rules = reactive({
  contract: [{ required: true, message: "请选择合同" }],
  nameOfPayment: [{ required: true, message: "请选择款项名称" }],
  returnAmount: [{ required: true, message: "请输入回款金额" }],
  collectionAccount: [{ required: true, message: "请选择收款账户" }],
  paymentVoucher: [{ required: true, message: "请上传回款凭证" }]
});

interface DrawerProps {
  title: string;
  id: number;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  title: "提交回款",
  id: 0
});
const params = ref({});

// 业务类型
const businessType = ref([
  { label: "111", value: 1 },
  { label: "222", value: 2 }
]);

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params;
  drawerVisible.value = true;
};

// 是否显示新建表单
const showAddForm = ref(false);

// 提交数据（新增/编辑）
const ruleFormRef = ref();
const handleSubmit = () => {
  ruleFormRef.value!.validate(async valid => {
    if (!valid) return;
    try {
      //   await drawerProps.value.api!(drawerProps.value.row);
      //   ElMessage.success({ message: `${drawerProps.value.title}用户成功！` });
      //   drawerProps.value.search!();
      //   drawerVisible.value = false;
    } catch (error) {
      console.log(error);
    }
  });
};

const emit = defineEmits(["close"]);
const close = () => {
  drawerVisible.value = false;
  emit("close");
};

defineExpose({
  acceptParams
});
</script>
